package com.example.service.teacher;

import com.example.entity.Account;
import com.example.entity.Teacher;
import com.example.exception.CustomException;
import com.example.mapper.TeacherMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * 教师登录
 */

@Service
public class TeacherLoginService {
    @Resource
    private TeacherMapper teacherMapper;

    public Teacher login(Account account) {
        String username = account.getUsername();
        Teacher teacher = teacherMapper.selectByUsername(username);
        if (teacher == null) {
            throw new CustomException("500", "教师不存在!");
        }
        String password = account.getPassword();
        if(!teacher.getPassword().equals(password)) {
            throw new CustomException("500", "工号或密码错误!");
        }
        return teacher;
    }
}
